Add GdkArray
authorBenjamin Otte <otte@redhat.com>
Thu, 2 Jul 2020 15:23:09 +0000 (17:23 +0200)
committerBenjamin Otte <otte@redhat.com>
Thu, 16 Jul 2020 16:09:57 +0000 (18:09 +0200)
commit8bf8ac50768e2ef543bd39f6340711f82fa5135b
treefd52df69cbc0687702855fb5b133fcf5760bba6c
parentb7efd896b6da21bd0810057c540c3eac59dc9e84
Add GdkArray

This is a scary idea where you #define a bunch of preprocessor values
and then #include "gdkarrayimpl.c" and end up with a dynamic array for
that data type.

See https://en.wikipedia.org/wiki/X_Macro for what's going on.

What are the advantages over using GArray or GPtrArray?

 * It's typesafe
   Because it works like C++ templates, we can use the actual type of
   the object instead of having to use gpointer.

 * It's one less indirection
   instead of 2 indirections via self->array->data, this array is
   embedded, so self->array is the actual data, and just one indirection
   away. This is pretty irrelevant in general, but can be very noticable
   in tight loops.

 * It's all inline
   Because the whole API is defined as static inline functions, the
   compiler has full access to everything and can (and does) optimize
   out unnecessary calls, thereby speeding up some operations quite
   significantly, when full optimizations are enabled.

 * It has more features
   In particular preallocation allows for avoiding malloc() calls, which
   can again speed up tight loops a lot.
   But there's also splice(), which is very useful when used with
   listmodels.
gdk/gdkarrayimpl.c [new file with mode: 0644]
testsuite/gdk/array.c [new file with mode: 0644]
testsuite/gdk/arrayimpl.c [new file with mode: 0644]
testsuite/gdk/meson.build